package com.freecloud.bittorrent.demo;

import cn.hutool.core.date.DateUtil;
import com.freecloud.bittorrent.demo.job.ScheduleJoinDHT;
import com.freecloud.bittorrent.demo.service.DHTServer;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @Author: maomao
 * @Date: 2021/11/22 3:47 下午
 */
@Slf4j
public class DownloadBTFileMain {

    public static DHTServer dhtServer = new DHTServer();

    public static void main(String[] args) throws SchedulerException {
        //定时任务
        startScheduleJob();
        dhtServer.start();
    }

    public static void startScheduleJob() throws SchedulerException {
        SchedulerFactory sf = new StdSchedulerFactory();
        Scheduler scheduler = sf.getScheduler();
        JobDetail jb =
            JobBuilder.newJob(ScheduleJoinDHT.class).withDescription("test job").withIdentity("testJob", "testGroup")
                .build();
        Trigger t = TriggerBuilder.newTrigger().withDescription("trigger").withIdentity("trigger", "triggerGroup")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/20 * * * * ?"))
            .startAt(DateUtil.offsetSecond(DateUtil.date(), 10)).forJob(jb).build();
        scheduler.scheduleJob(jb, t);
        scheduler.start();
    }
}
